package com.heima.search.listener;

import com.alibaba.fastjson.JSON;
import com.heima.model.search.enums.AppArticleInfo;
import com.heima.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class SearchListener {
    @Autowired
    private SearchService searchService;

    @KafkaListener(topics = "add.articleInfo.topic", groupId = "groupId1")
    public void addArticle(String message) {
        if (message==null){
            throw new RuntimeException("监听文章上传参数异常");
        }
        AppArticleInfo appArticleInfo = JSON.parseObject(message, AppArticleInfo.class);
        searchService.addApplication(appArticleInfo);
    }
}
